from playwright.sync_api import sync_playwright
 
with sync_playwright() as p:
    # 启动浏览器（headless=False显示界面）
    browser = p.chromium.launch(headless=False)
    page = browser.new_page()
    
    # 导航至目标页并断言标题
    page.goto("https://example.com")
    assert"Example Domain"in page.title()
    
    # 输入搜索词并提交
    page.locator("input#kw").fill("通讯")
    page.locator("button#go").click()
    
    # 等待结果加载并打印
    page.wait_for_timeout(1000)  # 简单等待（实际推荐用事件等待）
    results = page.locator(".result-item").all()
    for item in results:
        print(item.inner_text())
    
    browser.close()